<template>
	<view class="page">
		<u-sticky bg-color="#fff">
			<view :style="{ padding: '20rpx'}">
				<u-input v-model="queryForm.title" placeholder="搜索产品或者名称" suffix-icon="search" clearable
					suffix-icon-style="color: #909399" shape="circle" border="none" font-size="13px"
					@clear="clearSearch" @confirm="handleSearch" :custom-style="{
		      background: '#F4F4F4',
		      padding: '6px 12px',
		      boxShadow: '0 0 20rpx rgba(186, 186, 186, 0.1)',
		    }" />
			</view>
		</u-sticky>

		<view class="body">
			<view class="item" v-for="(item,index) in dataList" :key="index"
				@tap.stop="Jump(`/pages/home/learnDetails?id=${item.id}`)">
				<text class="overGame">{{item.test}}</text>
				<view class="top1">
					<image :src="$imageOss(item.image)" mode="widthFix" style="" class="image"></image>
					<view class="under">
						<view class="top">
							{{item.titile}}
						</view>
						<view class="bot">
							<text class="bot1">报名时间：{{item.application_start_time}}-{{item.application_end_time}}
							</text>
						</view>
						<view class="bot">
							<text class="bot1">开课时间：{{item.train_start_time}}-{{item.train_end_time}} </text>
						</view>
						<view class="bot" style="margin-top: 26rpx;">
							<view class="bot-icon">
								<Foot path="/pages/tabBar/learning" :comment="item.count" :like="item.like" :collect="item.collect" :type="2" :isShare="false" width="380"
									:is_like="item.is_like" :is_collect="item.is_collect" :is_id="item.id" @like="handleLike"></Foot>
							</view>
							<view class="bot2">
								<view class="" style="font-size: 28rpx;color: #466EC5;">
									{{item.registered}}
								</view>/{{item.limit}}人
							</view>
						</view>
					</view>
				</view>
			</view>
			<u-loadmore :status="status" />
		</view>
	</view>
</template>
<script>
	import CardItem from "@/components/CardItem/index";
	import vvSelect from '@/components/vv-select/index.vue'
	import Foot from "@/components/footer/index";
	import {
		trainList
	} from "@/request/homeApi.js";
	export default {
		components: {
			CardItem,
			vvSelect,
			Foot
		},
		data() {
			return {
				queryForm: {
					title: '',
					train_category_id: '',
					type: '',
					page: 1,
					limit: 10,
					recommend: '',
				},
				total: 0, // 总数
				dataList: [],
				status: "nomore", // 加载状态,
			};
		},
		onReachBottom() {
			let that = this
			if (that.queryForm.page < that.last_page) {
				that.queryForm.page = that.queryForm.page + 1
				that.getList()
			}
		},
		onShow() {
			this.queryForm.page = 1
			console.log(this.queryForm.page,'page')
			this.dataList = []
			this.queryForm.title = uni.getStorageSync('title') ? uni.getStorageSync('title') : ''
			this.getList();
		},
		onHide(){
			uni.removeStorageSync('title')
		},
		methods: {
			// 点赞/收藏
			handleLike() {
				this.dataList = []
				this.getList()
			},
			// 跳转
			Jump(url) {
				uni.navigateTo({
					url: url
				})
			},

			// 获取数据列表
			getList() {
				this.status = "loading";
				let that = this
				trainList(that.queryForm).then(res => {
					if (res.code == 200) {
						that.dataList = that.dataList.concat(res.data.list)
						that.last_page = Math.ceil(res.data.count / res.data.list.length)
						res.data.count == 0 ? that.status = 'nomore' : that.status = ''
					}else{
						uni.showToast({
							title: res.msg,
							duration: 1500,
							icon: 'none',
						})
					}
				})
			},

			// 搜索
			handleSearch() {
				this.queryForm.page = 1;
				this.dataList = []
				this.getList();
			},

			// 清空搜索框
			clearSearch() {
				this.queryForm.title = ''
				this.queryForm.page = 1;
				this.dataList = []
				this.getList();
			},
		},
	};
</script>
<style lang="scss" scoped>
	.page {
		.chooseCup {
			margin-right: 8rpx !important;

			image {
				width: 20rpx !important;
				height: 12rpx !important;
				margin: 14rpx;
			}
		}

		.body {
			// background: #F4F4F4;
			padding: 10rpx 0;
			display: flex;
			flex-direction: column;

			.item {
				padding: 10rpx 0 20rpx;
				background-color: #fff;
				position: relative;

				.overGame {
					border-bottom-right-radius: 20rpx;
					background: rgba(0, 0, 0, 0.70);
					padding: 10rpx 46rpx;
					color: #FFF;
					font-size: 24rpx;
					font-style: normal;
					font-weight: 500;
					position: absolute;
					top: 10rpx;
					left: 0rpx;
					z-index: 60;
				}

				.top1 {
					display: flex;
					flex-direction: column;

					.under {
						margin: 0 26rpx;
						border-bottom: 2rpx solid #D9D9D9;
						padding-bottom: 24rpx;
					}

					.image {
						height: 440rpx !important;
						width: 100%;
					}

					.top {
						color: #313131;
						font-family: PingFang SC;
						font-size: 30rpx;
						font-style: normal;
						font-weight: 400;
						line-height: normal;
						margin-top: 20rpx;
					}

					.bot {
						display: flex;
						flex-direction: row;
						justify-content: space-between;
						margin-top: 14rpx;

						.bot1 {
							color: #909090;
							font-family: PingFang SC;
							font-size: 26rpx;
							font-style: normal;
							font-weight: 400;
							line-height: normal;
						}

						.bot-icon {
							color: #909090;
							display: flex;
							font-family: PingFang SC;
							font-size: 26rpx;
							font-style: normal;
							font-weight: 400;
							line-height: normal;

							.box {
								display: flex;
								align-items: center;
								margin-right: 20rpx;
							}
						}

						.bot2 {
							color: #909090;
							font-family: PingFang SC;
							font-size: 24rpx;
							font-style: normal;
							font-weight: 400;
							line-height: normal;
							margin-top: 40rpx;
							display: flex;
							vertical-align: center;
						}
					}
				}

				.other {
					display: flex;
					justify-content: space-between;
					margin-top: 20rpx;
					flex-direction: row-reverse;

					.left {
						width: 160rpx;
						height: 122rpx;
						margin-left: 20rpx;

						.image {
							border-radius: 8rpx;
							width: 100%;
							height: 100%;
						}
					}

					.right {
						flex: 1;
						display: flex;
						flex-direction: column;
						justify-content: space-between;

						.top {}

						.bot {
							display: flex;
							flex-direction: column;
							justify-content: space-between;

							.bot1 {
								color: #909090;
								font-family: PingFang SC;
								font-size: 24rpx;
								font-style: normal;
								font-weight: 400;
								line-height: normal;
							}

							.bot2 {
								color: #313131;
								font-family: PingFang SC;
								font-size: 20rpx;
								font-style: normal;
								font-weight: 400;
								line-height: normal;
								margin-top: 10rpx;
							}
						}
					}
				}
			}

			.f-bottom {
				font-weight: 600;
				font-size: 28rpx;
				color: $active-color;
				margin-left: 20rpx;

				text:nth-child(2) {
					font-size: 24rpx;
				}

				text:last-child {
					font-size: 40rpx;
				}
			}
		}

		.tabBox {
			display: flex;
			justify-content: space-evenly;
			width: 100%;
			padding: 10rpx 0 0;
			box-sizing: border-box;
			text-align: center;
			font-size: 30rpx;

			/deep/.u-scroll-list {
				width: 100%;
				padding-bottom: 0;
			}

			.leftIcon {
				width: 120rpx;
				height: 3rpx;
				margin: 14rpx auto;
			}

			.navItem {
				width: 160rpx;
				text-align: center !important;
				overflow: hidden;
			}
		}
	}
</style>
